home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / MPW Related / Animated Cursors / ShowCursor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-14  |  6.5 KB  |  243 lines  |  [TEXT/MPS ]

  1. /******************************************************************************\
  2. * Header Files
  3. \******************************************************************************/
  4.  
  5. #include <Desk.h>
  6. #include <Events.h>
  7. #include <Memory.h>
  8. #include <Menus.h>
  9. #include <OSUtils.h>
  10. #include <Resources.h>
  11. #include <SegLoad.h>
  12. #include <Traps.h>
  13. #include <Windows.h>
  14. #include "ShowCursor.h"
  15. #include "CursorTkl.h"
  16. #include "CursWindTkl.h"
  17. #include "MenuTkl.h"
  18. #include "ShutDown.h"
  19. #include "Startup.h"
  20. #include "WindowTkl.h"
  21.  
  22.  
  23. /******************************************************************************\
  24. * Constant Declarations
  25. \******************************************************************************/
  26.  
  27. #define susResSelector       0x01 //Selector for suspend/resume event
  28. #define suspendResumeMessage 1    //Bit for suspend/resume messages
  29.  
  30. /* True if suspend/resume message is for resume */
  31. #define suspResIsResume(Message) ((short) ((Message) & 0x00000001L))
  32.  
  33.  
  34. /******************************************************************************\
  35. * Function Declarations
  36. \******************************************************************************/
  37.  
  38. void  main (void);
  39. void  EventLoop (void);
  40. void  DoMouseEvent (EventRecord *);
  41. void  DoKeyEvent (EventRecord *);
  42. void  DoMFEvent (EventRecord *);
  43.  
  44.  
  45. /******************************************************************************\
  46. * Global Variables
  47. \******************************************************************************/
  48.  
  49. short     gApplErr;    //Application error
  50. short     gFlags;      //Application flags
  51. WindowPtr gLastWindow; //Active window during last iteration of event loop
  52. SysEnvRec gEnvirons;   //Current Environment
  53.  
  54.  
  55. /******************************************************************************\
  56. * Macro Declarations
  57. \******************************************************************************/
  58.  
  59. /* Return event record byte which indicates suspend or resume */
  60. #define app4Selector(EventPtr) (*((unsigned char *) & (EventPtr)->message))
  61.  
  62. /* Check to see if a trap is available */
  63. #define trapAvailable(Num,Type) (NGetTrapAddress (Num, Type) != GetTrapAddress \
  64.         (_Unimplemented))
  65.  
  66.  
  67. #pragma segment Main
  68. /******************************************************************************\
  69. * Entry to ShowCursor
  70. \******************************************************************************/
  71.  
  72. void
  73. main ()
  74.     {
  75.     WindowPtr CursWind;
  76.  
  77.     UnloadSeg (Startup);
  78.     MaxApplZone ();
  79.     MoreMasters ();
  80.     MoreMasters ();
  81.     MoreMasters ();
  82.     Startup ();
  83.     UnloadSeg (Startup);
  84.     if (gApplErr == noApplErr)
  85.         {
  86.         CursWind = CreateCursWind ();
  87.         if (gApplErr == noApplErr)
  88.             EventLoop ();
  89.         }
  90.     ShutDown ();
  91.     ExitToShell ();
  92.     }
  93.  
  94.  
  95. #pragma segment Main
  96. /******************************************************************************\
  97. * EventLoop - Main event loop
  98. *
  99. * EventLoop is the main event loop.  It retrieves events and delegates power
  100. * to the appropriate handler depending on the type of event.
  101. \******************************************************************************/
  102.  
  103. static void
  104. EventLoop ()
  105.     {
  106.     EventRecord TheEvent;       //Usual event record
  107.     short       EventOccured;   //True if a non-null event occured
  108.     WindowPtr   NewFront;       //New frontmost window
  109.     short       WNEImplemented; //True if WaitNextEvent implemented
  110.     long        SleepTime;      //Amount of time can sleep under MF
  111.  
  112.     WNEImplemented = (short) trapAvailable (_WaitNextEvent, ToolTrap);
  113.     SleepTime = -1L;
  114.     while (!(gFlags & quitFlag))
  115.         {
  116.         if ((NewFront = FrontWindow ()) != gLastWindow)
  117.             {
  118.             if ((NewFront != (WindowPtr) null) && ((WindowPeek) NewFront)->
  119.                     windowKind < 0)
  120.                 SleepTime = 10L;
  121.             else
  122.                 SleepTime = -1L;
  123.             FixMenuDim ();
  124.             gLastWindow = NewFront;
  125.             }
  126.         FixCursor ();
  127.         if (WNEImplemented)
  128.             EventOccured = WaitNextEvent (everyEvent, &TheEvent, SleepTime,
  129.                     (RgnHandle) null);
  130.         else
  131.             {
  132.             SystemTask ();
  133.             EventOccured = GetNextEvent (everyEvent, &TheEvent);
  134.             }
  135.         if (EventOccured)
  136.             {
  137.             switch (TheEvent.what)
  138.                 {
  139.                 case mouseDown:
  140.                     DoMouseEvent (&TheEvent);
  141.                     break;
  142.                 case keyDown:
  143.                     DoKeyEvent (&TheEvent);
  144.                     break;
  145.                 case updateEvt:
  146.                     DoUpdateEvent (&TheEvent);
  147.                     break;
  148.                 case activateEvt:
  149.                     DoActivateEvent ((WindowPeek) TheEvent.message, TheEvent.
  150.                             modifiers & (short) activeFlag);
  151.                     break;
  152.                 case app4Evt:
  153.                     DoMFEvent (&TheEvent);
  154.                     break;
  155.                 default:
  156.                     break;
  157.                 }
  158.             }
  159.         }
  160.     }
  161.  
  162.  
  163. #pragma segment Main
  164. /******************************************************************************\
  165. * DoMouseEvent - Handle mouse-down event
  166. *
  167. * DoMouseEvent handles a mouse-down event by delegating power to the appropriate
  168. * handler depending on the type of event.
  169. \******************************************************************************/
  170.  
  171. static void
  172. DoMouseEvent (TheEvent)
  173.     EventRecord *TheEvent; //Event from main event loop
  174.     {
  175.     WindowPtr      ClickWind; //-> Window that was clicked, if any
  176.     register short PartCode;  //Code of part that was clicked
  177.  
  178.     switch (PartCode = FindWindow (TheEvent->where, &ClickWind))
  179.         {
  180.         case inMenuBar:
  181.             DoMenuEvent (MenuSelect (TheEvent->where));
  182.             break;
  183.         case inSysWindow:
  184.             SystemClick (TheEvent, ClickWind);
  185.             break;
  186.         case inContent:
  187.             DoContentEvent (TheEvent, ClickWind);
  188.             break;
  189.         case inDrag:
  190.             DoDragEvent (TheEvent, ClickWind);
  191.             break;
  192.         case inGoAway:
  193.             DoGoAwayEvent (TheEvent, ClickWind);
  194.             break;
  195.         case inZoomIn:
  196.         case inZoomOut:
  197.             DoZoomEvent (TheEvent, ClickWind, PartCode);
  198.             break;
  199.         default:
  200.             break;
  201.         }
  202.     }
  203.  
  204.  
  205. #pragma segment Main
  206. /******************************************************************************\
  207. * DoKeyEvent - Handle key-down event
  208. *
  209. * DoKeyEvent handles a key-down event by delegating power to the appropriate
  210. * handler depending on the type of event.
  211. \******************************************************************************/
  212.  
  213. static void
  214. DoKeyEvent (TheEvent)
  215.     EventRecord *TheEvent; //Event from main event loop
  216.     {
  217.     if (TheEvent->modifiers & cmdKey)
  218.         DoMenuEvent (MenuKey ((char) TheEvent->message));
  219.     }
  220.  
  221.  
  222. #pragma segment Main
  223. /******************************************************************************\
  224. * DoMFEvent - Handle MultiFinder event
  225. *
  226. * DoMFEvent handles suspend and resume events.
  227. \******************************************************************************/
  228.  
  229. static void
  230. DoMFEvent (TheEvent)
  231.     EventRecord *TheEvent; //Event from main event loop
  232.     {
  233.     WindowPeek TheWind; //-> Window to activate/deactivate
  234.  
  235.     if (TheEvent->message >> 24 == suspendResumeMessage)
  236.         {
  237.         if (suspResIsResume (TheEvent->message))
  238.             /* Do Resume Stuff */;
  239.         else
  240.             /* Do Suspend Stuff */;
  241.         }
  242.     }
  243.